#cleaning the data
#filter food courts whose licsense status is active and VIOLDTTM in 2018.
boston_food <- mayorsfoodcourt %>% filter(str_detect(VIOLDTTM, "2018")) %>% filter(LICSTATUS=="Active") %>% separate(Location, c("lat","long"),",") %>% filter(!is.na(long) & !is.na(lat))
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 12663 rows
## [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 101, 154,
## 155, 156, ...].
#covert location into latitude and longtitude.
boston_food$lat <- as.numeric(gsub("\\(", "", boston_food$lat))
boston_food$long <- as.numeric(gsub(")", "", boston_food$long))
#View(boston_food)
#leaflet
content <- paste(sep = "<br/>",
boston_food$businessName,
boston_food$Address)
boston.500 <- boston_food[1:500,]
getColor <- function(boston_food) {
sapply(boston_food$ViolStatus, function(ViolStatus) {
if(ViolStatus == "Pass") {
"purple"
} else if(ViolStatus == "Fail"){
"green"
} })
}
icons <- awesomeIcons(
icon = "coffee",
iconColor = 'white',
library = 'ion',
markerColor = getColor(boston.500)
)
# Show first 200 rows from the boston_food dataset
leaflet(boston.500) %>% addTiles() %>% addAwesomeMarkers(~long, ~lat, icon=icons, popup = ~content, options = popupOptions(closeButton = FALSE), label = ~as.character(ViolStatus))%>% addLegend("bottomright",colors=c("green","purple"),labels = c("Pass","Fail"),title = "Violstatus", opacity = 1)
#%>% addProviderTiles(providers$Esri.NatGeoWorldMap)
boston_map<- make_bbox(lat = lat, lon = long, data = boston_food)
boston_map <- get_map(location = boston_map, source = "google", maptype = "hybrid")
## Warning: bounding box given to google - spatial extent only approximate.
## converting bounding box to center/zoom specification. (experimental)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=42.315345,-71.086035&zoom=12&size=640x640&scale=2&maptype=hybrid&language=en-EN&sensor=false
ggmap(boston_map) +
geom_point(data = boston_food, mapping = aes(x = long, y = lat, color= ViolStatus))
